
public class FindTriangleProperties {

	/**
	 * @param args
	 */
public static void main(String[] args) {
		
		final int numOfSides = 3;
		double side[] = new double [numOfSides];
		boolean right = false;

		//Error Checking to correct Test case 1 (Wrong Number of Inputs)
		if (args.length != numOfSides){
			System.out.println("Incorrect Usage.  Please give three numbers as input");
			System.exit(1);
		}
		
		// Collect Input
		for (int i = 0; i < numOfSides; i++){
			//Error Checking for case 1 (Not a Number)
			try{
				side[i] = Double.parseDouble(args[i]);
			} catch (NumberFormatException nfe) {
				System.out.println("Incorrect Usage.  " + args[i] + " is not a number.");
				System.exit(1);
			}	
		}
		
		//  Simple Sort for 3 numbers
			if (side[0] > side [1]){
				if(side [0] > side [2]){
					if (side [1] > side [2]){
						// 210
						double temp = side[0];
						side[0] = side[2];
						side[2] = temp;
					} else{
						// 120
						double temp = side[0];
						side[0] = side[1];
						side[1] = side[2];
						side[2] = temp;
					}
				}else {
					//102
					double temp = side[0];
					side[0] = side[1];
					side[1] = temp;
				}
			} else {
				if(side [1] > side [2]){
					if (side [0] > side [2]){
						// 201
						double temp = side[0];
						side[0] = side[2];
						side[2] = side[1];
						side[1] = temp;
					} else{
						// 021
						double temp = side[1];
						side[1] = side[2];
						side[2] = temp;
					}
				}else {
					//012 Already Sorted
				}
			}
		
		// Checking for Test Case 2, 3, and 4
		if (side[0] < 0){
			System.out.println("A Triangle can not have a negative length side.");
			System.exit(1);
		} else if(side [0] == 0){
			System.out.println("A Triangle can not have a 0 length side.");
			System.exit(1);
		} else if(side[0] + side[1] <= side[2]){
			System.out.println("These three lengths do not make a triangle.");
			System.exit(1);
		}
		

		//After Moving up sort, Some performance improvements can be made here.
		
		//Check For right Triangle.  Now using sqrt(a^2 + b^2) = c so C^2 does not need to be calculated.
		if (Math.sqrt(Math.pow(side[0],2) + Math.pow(side[1],2)) == side[2])
			right = true;
		
		// Classify Triangle
		if(side[0] == side[1] && side[1] == side[2]){//Check for Equilateral
			System.out.println("The triangle is Equilateral.\nIt is NOT a right triangle");
			System.exit(0);
		} else if(side[0] == side[1] || side[1] == side[2] || side[0] == side[2]){ // check for Isosceles
			System.out.println("The triangle is Isosceles.");
			if(right){
				System.out.println("It is a right triangle");
				System.exit(0);
			}else{
				System.out.println("It is NOT a right triangle");
				System.exit(0);
			}
		}else{
			System.out.println("The triangle is Scalene.");
			if(right){
				System.out.println("It is a right triangle");
				System.exit(0);
			}else{
				System.out.println("It is NOT a right triangle");
				System.exit(0);
			}
		}	
	}

}